package UPPM;

import java.util.ResourceBundle;
import java.util.concurrent.TimeUnit;

import junit.framework.Assert;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

import com.packt.webdriver.chapter1.isDisplayed;

public class TestMainMenu
{
	private void syso() {
		String print = "Testing TestMainMenu";
		System.out.println(print);
	}
	WebDriver driver = new FirefoxDriver();

	@Before
	public void setUp() throws Exception {
		driver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS);
		driver.manage().window().maximize();
		driver.get("http://test.unippmtest.co.uk");	
		}

	@Test
	 public void testMainMenuInitialStateNotLoggedIn() throws Exception
	    {
		WebElement home = driver.findElement(By.xpath(".//*[@id='Image1']"));
		Assert.assertEquals( true, home.isDisplayed());
		WebElement new_Rel = driver.findElement(By.xpath(".//*[@id='header-links']/ul/li[1]/a/font/strong"));
		Assert.assertEquals("New Releases", new_Rel.getText());
		WebElement news = driver.findElement(By.xpath(".//*[@id='header-links']/ul/li[3]/a"));
		Assert.assertEquals("Composers", news.getText());
		WebElement reviews = driver.findElement(By.xpath(".//*[@id='header-links']/ul/li[2]/a"));
		Assert.assertEquals("News", reviews.getText());
		WebElement help = driver.findElement(By.xpath(".//*[@id='header-links']/ul/li[6]/a"));
		Assert.assertEquals("Help", help.getText());
		WebElement liveChat = driver.findElement(By.xpath(".//*[@id='anonymous-view']/ul/li[1]/a"));
		Assert.assertEquals("Live Chat", liveChat.getText().trim());
	    }
	
	@Test
	 public void testMainMenuInitialStateLoggedIn() throws Exception {
	    Thread.sleep(1000);
		Utils.Login(driver);
		
		//check header
		WebElement homeEl = driver.findElement(By.xpath(".//*[@id='Image1']"));
		Assert.assertEquals( true, homeEl.isDisplayed());
		WebElement new_Rel = driver.findElement(By.xpath(".//*[@id='header-links']/ul/li[1]/a/font/strong"));
		Assert.assertEquals("New Releases", new_Rel.getText());
		WebElement news = driver.findElement(By.xpath(".//*[@id='header-links']/ul/li[3]/a"));
		Assert.assertEquals("Composers", news.getText());
		WebElement reviews = driver.findElement(By.xpath(".//*[@id='header-links']/ul/li[2]/a"));
		Assert.assertEquals("News", reviews.getText());
		WebElement licensing = driver.findElement(By.xpath(".//*[@id='header-links']/ul/li[5]/a"));
		Assert.assertEquals("Licensing", licensing.getText());
//		WebElement cue_sheets = driver.findElement(By.xpath("//*[@id='outline']/div/div[2]/div[3]/div[1]/ul/li[6]/a/span/span"));
//		Assert.assertEquals("Cue Sheets", cue_sheets.getText());
		WebElement help = driver.findElement(By.xpath(".//*[@id='global_help_btn']"));
		Assert.assertEquals("Help Panels:off", help.getText().trim());
		WebElement liveChat = driver.findElement(By.xpath(".//*[@id='login-view']/ul/li[1]/a"));
		Assert.assertEquals("Live Chat", liveChat.getText().trim());
	    }
	
	@After
	public void tearDown() throws Exception {
		System.out.println("******************************");
		driver.quit();
	}
}
